package common.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.ImageContain;
	import lz.controls.LItem;
	import lz.controls.PowerGraphics;
	import lz.controls.managers.TipsManager;
	import lz.controls.nick.NumberUtils;
	import lz.controls.nick.SpiderShape;

	/**
	 *基础球员卡item 
	 * @author lake
	 * 
	 */	
	public class BasePlayerCardItem extends LItem implements IComponent
	{
		/**
		 * 球员名字 
		 */
		protected var _playerName		:TextField;
		/**
		 *位置 
		 */
		protected var _place			:TextField;
		/**
		 *等级 
		 */
		protected var _lv				:TextField;
		/**
		 *号码 
		 */
		protected var _number			:TextField;
		/**
		 *能力值 
		 */
		protected var _abiliy			:TextField;
		/**
		 *头像容器 
		 */
		protected var _picture			:MovieClip;
		/**
		 *蜘蛛图 
		 */
		protected var _spider			:MovieClip;
		/**
		 *头像 
		 */
		protected var _image			:ImageContain;
		/**
		 * 图形
		 */		
		protected var _spiderShape		:SpiderShape;
		/**
		 *号码容器 
		 */
		protected var _numberContain	:MovieClip;
		/**
		 *能力值数组 
		 */		
		protected var powers			:Array = [0,0,0,0,0,0];
		
		public function BasePlayerCardItem()
		{
			super();
		}
		/**
		 *设置数据 
		 * @param value
		 * 
		 */		
		override public function set data(value :*):void
		{
			_data = value;
			var vo :PlayerVo = value as PlayerVo;
//			_playerName.text = vo.pname + "";
//			_place.text = vo.place + "";
//			_lv.text = "Lv"+ vo.grade;
//			DisplayObjectUtil.removeAllChildren(_numberContain);
//			NumberUtils.playercardNumberToBitmap(_numberContain,vo.number);
//			_abiliy.text = vo.abiliy.toString();
//			//头像
//			setImage(vo.headurl1);
//			//能力图
//			powers = [vo.s2,vo.s1,vo.s6,vo.s5,vo.s4,vo.s3];
//			/*var powers:Array = [vo.s2,vo.s1,vo.s6,vo.s5,vo.s4,vo.s3];
//			var powerGraphics :PowerGraphics = new PowerGraphics();
//			powerGraphics.powers = powers;
//			_spider.addChild(powerGraphics);
//			_spider.mouseChildren = false;*/
//			if(_spiderShape == null)
//			{
//				_spiderShape = new SpiderShape();
//				_spider.addChild(_spiderShape);
//				_spiderShape.x = (_spider.width>>1) + 0.8;
//				_spiderShape.y = (_spider.height>>1)+0.3;
//			}
//			_spiderShape.setData([[vo.s1,90],[vo.s2,30],[vo.s3,330],
//				[vo.s4,270],[vo.s5,210],[vo.s6,150]],0x6beaea,.4);
//			//color back
//			_symbolSkin.gotoAndStop(vo.colorFrame);
		}
		/**
		 *设置头像 
		 * @param $url
		 * 
		 */		
		private function setImage($url:String):void
		{
			var fBitmapData :BitmapData 
			//= AppData.getInstance().shopDataManager.getGoodBitmapDataByUrl($url);
			if(fBitmapData)
			{
				_picture.addChild(new Bitmap(fBitmapData));
			}
			else
			{
				if(_image == null)
				{
					_image = new ImageContain();
					_image.setSize(50,50);
					_picture.addChild(_image);
				}
				_image.addEventListener(IOErrorEvent.IO_ERROR,onIoErrorHandler);
				_image.url = $url;
			}
		}
		/**
		 *io 错误
		 * @param e
		 *
		 */
		private function onIoErrorHandler(e:IOErrorEvent):void
		{
			var imgContain:ImageContain=e.target as ImageContain;
			imgContain.removeEventListener(IOErrorEvent.IO_ERROR, onIoErrorHandler);
			var fBitmapData:BitmapData //= AppData.getInstance().shopDataManager.getGoodBitmapDataByUrl(AppData.getInstance().playerDefaultImg);
			if (fBitmapData)
			{
				_picture.addChild(new Bitmap(fBitmapData));
			}
			else
			{
				imgContain.url=AppData.getInstance().playerDefaultImg;
			}
		}
		/**
		 *初始化 
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.liangzhong.ui.playCard");
			this.addChild(_symbolSkin);
			_playerName 	= _symbolSkin._playerName;
			_place 			= _symbolSkin._place;
			_lv 			= _symbolSkin._lv;
			_number 		= _symbolSkin._number;
			_abiliy 		= _symbolSkin._abiliy;
			_picture 		= _symbolSkin._picture;
			_spider 		= _symbolSkin._spider;
			_numberContain 	= _symbolSkin._numberContain;
			_symbolSkin.gotoAndStop(1);
			addEvtListener();
		}
		/**
		 *添加事件 
		 * 
		 */		
		public function addEvtListener():void
		{
			_spider.addEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
			_spider.addEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
		}
		/**
		 *删除事件 
		 * 
		 */		
		public function removeEvtListener():void
		{
			_spider.removeEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
			_spider.removeEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
		}
		/**
		 *移上 
		 * @param e
		 * 
		 */		
		private function rollOverHandler(e :MouseEvent):void
		{
			var info :String = "";
			info += "进攻: " + powers[1] + " \n";
			info += "速度: " + powers[2] + " \n";
			info += "抢断: " + powers[3] + " \n";
			info += "控球: " + powers[0] + " \n";
			info += "防守: " + powers[4] + " \n";
			info += "力量: " + powers[5] + " \n";
			TipsManager.show("PlayerPropertyTips",{base:info},15,15);
		}
		/**
		 *移开 
		 * @param e
		 * 
		 */		
		private function rollOutHandler(e :MouseEvent):void
		{
			TipsManager.hide();
		}
		/**
		 *销毁 
		 */		
		public function destroyView():void
		{
			removeEvtListener();
			_image = null;
			_spiderShape = null;
			_picture = null;
			_spider = null;
			_symbolSkin = null;
		}
	}
}